<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yh.dao.ordersDao">

    <resultMap id="o_p" type="com.yh.javabean.Orders" autoMapping="true">
        <id column="id" property="id"></id>
        <association property="product" javaType="com.yh.javabean.Product" autoMapping="true">
            <id column="pid" property="id"></id>
        </association>
    </resultMap>

    <select id="selectAll" resultMap="o_p">
        select o.*,p.id pid,p.productNum,p.productName,p.cityName,p.departureTime,p.productPrice,p.productDesc,p.productStatus from orders o ,product p where o.productId=p.id
    </select>

    <select id="selectAllKey" resultMap="o_p">
        select o.*,p.id pid,p.productNum,p.productName,p.cityName,p.departureTime,p.productPrice,p.productDesc,p.productStatus
        from orders o ,product p
        where o.productId=p.id
        <if test="orderNum!=''">
            and o.orderNum=#{orderNum}
        </if>
        <if test="productName!=''">
            and p.productName like "%" #{productName} "%"
        </if>
    </select>


    <resultMap id="all" type="com.yh.javabean.Orders" autoMapping="true">
        <id column="id" property="id"></id>
        <association property="product" column="id" select="com.yh.dao.ProductDao.selectByOid" fetchType="eager"></association>
        <association property="member" column="id" select="com.yh.dao.MemberDao.selectByOid" fetchType="eager"></association>
        <collection property="travellers" column="id" select="com.yh.dao.TravellerDao.selectByOid" fetchType="eager"></collection>
    </resultMap>
    <select id="selectById" resultMap="all">
        select * from orders where id=#{id}
    </select>
</mapper>